package com.ruoyi.quartz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.quartz.service.ICustomerService;
import com.ruoyi.quartz.service.IOrderListService;
import com.ruoyi.system.domain.DTO.OrderListDto;
import com.ruoyi.system.domain.SysDictType;
import com.ruoyi.system.domain.vo.CustomerVo;
import com.ruoyi.system.domain.vo.OrderLogVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单信息
 * 
 */
@Controller
@RequestMapping("/business/customer")
public class CustomerController extends BaseController
{
    private String prefix = "business/customer";

    @Autowired
    private ICustomerService customerService;

    @RequiresPermissions("business:customer:view")
    @GetMapping()
    public String customer() {
        return prefix + "/customer";
    }

    @RequiresPermissions("business:customer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CustomerVo customerVo) {
        List<CustomerVo> customerVoList = new ArrayList<CustomerVo>();
        startPage();
        customerVoList = customerService.list(customerVo);
        return getDataTable(customerVoList);
    }

    /**
     * 新增字典类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存字典类型
     */
    @Log(title = "字典类型", businessType = BusinessType.INSERT)
    @RequiresPermissions("business:customer:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated CustomerVo customerVo)
    {
        customerVo.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(customerService.insertCustomerVo(customerVo));
    }

    /**
     * 修改字典类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("customer", customerService.selectCustomerVoById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存字典类型
     */
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @RequiresPermissions("business:customer:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated CustomerVo customerVo)
    {

        customerVo.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(customerService.updateCustomerVo(customerVo));
    }

    @Log(title = "客户删除", businessType = BusinessType.DELETE)
    @RequiresPermissions("business:customer:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(customerService.deleteCustomerVoById(ids));
    }


}
